/**
 * 
 */
package cn.edu.nju.ws.sview.wyge.relations.adataset.entities;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import cn.edu.nju.ws.sview.database.DBConnectionFactory;
import cn.edu.nju.ws.sview.wyge.relations.adataset.CustomDataset;

/**
 * @author Weiyi Ge (geweiyi@gmail.com) 2012-8-1
 * 
 */
public class HasNamedEntities {
	public static void main(String[] argus){
		System.out.println(judge("uri", 49417894));
	}
	
	public static boolean judge(String ds_type, int ds_id) {
		ArrayList<Integer> docs = null;
		if (ds_type.equals("custom")) {
			docs = CustomDataset.getURLIDsByCustomDatasetId(ds_id);
		} else if (ds_type.equals("uri")) {
			docs = new ArrayList<Integer>();
			docs.add(ds_id);
		}
		return judge(docs);
	}

	public static boolean judge(ArrayList<Integer> docs) {
		boolean ret = false;
		String docstring = "";
		for (int doc : docs) {
			docstring += doc + ",";
		}
		docstring = docstring.substring(0, docstring.length() - 1);

		try {
			Connection con = DBConnectionFactory.getConnection();//.getFalconConnection();
			Statement stmt = con.createStatement();
			String a = String.format(
					"SELECT s FROM quadruple where doc_id in (%s)", docstring)
					+ " and s like \"u%\" limit 1";
			ResultSet rs = stmt.executeQuery(a);//主语为uri
			if (rs.next()) {
				ret = true;
			}
			rs.close();
			stmt.close();
			con.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return ret;
	}
}
